package main

import (
	"fmt"
	"time"
)

/**
网上看看那个两个协程交替输出奇偶数，或者26个字母的，基本也就这些了
*/

func pa(int2 int, ch chan struct{}) {
	<-ch
	fmt.Println("协程1偶数：", string(int2))
	time.Sleep(time.Second)

}
func pb(int2 int, ch chan struct{}) {
	<-ch
	fmt.Println("协程2奇数：", string(int2))
	time.Sleep(time.Second)
}

func main() {

	var c = make(chan struct{}, 1)
	c1 := c
	str := "abcdefghijklmnoptrstuvwxyz"
	for i := 0; i < len(str); i++ {
		if str[i]%2 == 0 {
			c <- struct{}{}
			go pa(int(str[i]), c)
		} else {
			c1 <- struct{}{}
			go pb(int(str[i]), c1)
		}
	}
	time.Sleep(time.Hour)

}
